<!DOCTYPE html>
<html>
<head>
	<title>NexHome</title>
    
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	
    <!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    <!--<link href="css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />-->

    <!-- libraries -->
   <link href="css/lib/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" />
    <link href="css/lib/font-awesome.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/layout.css" />
    <link rel="stylesheet" type="text/css" href="css/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/icons.css" />

    <!-- this page specific styles -->
	<link rel="stylesheet" href="css/cfgmgr/bootstrap-table.css">    
 <!-- this page specific styles -->
    <link rel="stylesheet" href="css/compiled/index.css" type="text/css" media="screen" />
	<link rel="stylesheet" href="css/cfgmgr/clean.css" type="text/css" media="screen" /> 
 

    <!-- open sans font -->
    <link href='css/OpenSans.css' rel='stylesheet' type='text/css' />

    <!-- lato font -->
    <link href='css/Lato.css' rel='stylesheet' type='text/css' />
	
<!--[if lt IE 9]>
      <script src="js/html5.js"></script>
    <![endif]--> 
	 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
	a{cursor:pointer}
	a {
  color: #0088cc;
  text-decoration: none;
} 	
	</style>
	<script>
	function JumpTOcfgUPPage(username)
	{
		if(username == null || username == "" || username == 'undefined'){
		alert("设备NID为空");
		return;
		}
		parent.Reload_cfgUpload(username);
				
	}
	function JumpTOcfgPage(username)
	{
		if(username == null || username == "" || username == 'undefined'){
		alert("设备NID为空");
		return;
		}
		parent.Reload_cfgMgr(username);
				
	}
	function JumpTOOAMPage(username, num, online)
	{
		if(username == null || username == "" || username == 'undefined'){
		alert("设备NID为空");
		return;
		}
		parent.Reload_devOAM(username, num, online);
				
	}
	</script>
</head>
<body>



	<!-- main container -->
    <div class="content">       
        <div class="container-fluid">
         <div id="pad-wrapper" class="users-list">

               <div class="row-fluid header">
                    <h3>设备列表&nbsp;&nbsp;&nbsp;<a id="ViewAllbtn"><i class="icon-refresh"></i></a></h3>
                    <div class="span10 pull-right">
                        <input type="text" class="span5" style="margin: 0;padding: 2px 6px;" id="SearchUserTxt" placeholder="输入设备SN或NID" onkeydown="return entersearch(event);" />
						<a id="cleanBtn" onclick="cleanIput()" style="position: relative; margin:-25px -25px;color: #9ba8b6"><i class="icon-search"></i></a>

						&nbsp;
						<div class="ui-dropdown" style="margin: 0px 31px">
                            <div class="head" data-toggle="tooltip" title="Click me!" id="SearchUserbtn">
                                设备筛选
                                
                            </div>  
                            
                               
                        </div>
						
						
                    </div>
					 
                    
                </div>
				  <div class="row-fluid chart" id="router">
                    <div class="row-fluid head">
                        <div class="span12">
                            <h4 style="margin:0 0 0 0">设备列表信息 <small>显示当前工程商可管理的设备信息列表</small></h4>
                        </div>
                    </div>
				</div>
				<div class="table-wrapper table-products" >
					
					 <div class="row-fluid table">
						<table id="table-sublist" ></table>
					</div>
				 </div>
				
				 <div class="table-wrapper" style=" margin-bottom::10px;">
					
					
				 </div>
				
				
            </div>
        </div>
    </div>
<div class="modal small hide fade" id="devRemarkModel" tabindex="-1" role="dialog" aria-labelledby="floorAddModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3>设备说明设置</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form id="SetRemarkform">
					<table id="RemarkSetTable">						
						<tr hidden="hidden"><td>设备ID</td><td><input type="text" id="devId" name="devId" class="input-xlarge" ></td></tr>
						<tr><td>设备说明</td><td><input type="text" id="devRemarkMsg"  name="devRemarkMsg"  validate="max_length[24]" class="input-xlarge" ></td></tr>						
					</table>					
					</form>
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger"  id="setDevRemarkBtn">添加</button>
				</div>
</div> 

	<!-- scripts -->
	<script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/jquery-latest.js"></script>
    <script src="js/bootstrap.min.js"></script>
	<script src="js/cfgmgr/table/bootstrap-table.js"></script>
<script src="js/cfgmgr/table/bootstrap-table-zh-CN.js"></script>
    <script src="js/jquery-ui-1.10.2.custom.min.js"></script>  
    <script src="js/theme.js"></script>
	<script src="js/bootbox.min.js"></script>
	
    <script type="text/javascript">
	var DevModifyInfo;
	var Modname = "";
	var Modmsk = '1';
	var CurrorgAccount = '';
	var sKeyVal = '';
	var currid=parent.CurrorgID;
	
function request()
{ 
	var url = location.href;
	var paraString;
	if(url.indexOf("username") != -1){ 
 	paraString = url.substring(url.indexOf("=")+1,url.length);	 
	}
	else{
	paraString = "NO";
	}
	return paraString;  	
	
}

	$(function () {
		
		currid=parent.CurrorgID;
		
		
	$('#table-sublist').bootstrapTable({
	method: 'get',
	url: "../adminMgr/device/loadDeviceList",
	//height: 486,
	striped: true,
	dataType: "json",
	timeout: 100000,
	cache: false,
	pagination: true,
	"queryParamsType": "limit",
	singleSelect: false,
	contentType: "application/x-www-form-urlencoded",
	pageSize: 10,
	pageNumber:1,
	pageList: [10, 25, 50, 100],
	showRefresh: false,
	showToggle: false,	
	search: false, //不显示 搜索框
	showColumns: false, //不显示下拉框（选择显示的列）
	sidePagination: "server", //服务端请求
	queryParams: sublistqueryParams,
	responseHandler: sublistresponseHandler,
	columns: [
			
		{
			field: 'id',	
			title: 'ID',	
			width: '5%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},
		{
			field: 'sn',	
			title: 'SN',	
			width: '13%',	
			align: 'center',	
			valign: 'middle',
			formatter: jumpTodevMngFormatter,	
			sortable: false	
		},
		{
			field: 'nid',	
			title: 'NID',	
			width: '12%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},
		{
			field: 'online',	
			title: '在线状态',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',
			formatter: onlineFormatter,
			sortable: false	
		},
		{
			field: 'remark',	
			title: '说明',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',
			
			sortable: false	
		},{
			field: 'version',	
			title: '当前版本',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',
			sortable: false	
		},{
			field: 'upgrade',	
			title: '版本升级',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',
			formatter: upgradeFormatter,
			sortable: false	
		},
		{
			field: 'modify',
			title: '编辑说明',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',
			formatter: remarkFormatter,	
			sortable: false	
		},
		{
			title: '配置文件上传/下载',
			field: 'load',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',	
			formatter: cfgUploadFormatter,				
			sortable: false	
		},
		{
			title: '配置管理',
			field: 'manager',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',	
			formatter: cfgMgrFormatter,				
			sortable: false	
		}
		
	]/*,
	onLoadSuccess:function(){

                },
	onLoadError: function () {
		alert("数据加载失败！");
	}*/
});
if(currid == '' || currid == undefined || currid == 'undefined' || currid == null)
{
	currid=parent.CurrorgID;
	$('#table-sublist').bootstrapTable('refresh',{url:'../adminMgr/device/loadDeviceList'});
}
$('#ViewAllbtn').click(function(e){
		e.preventDefault();
		$('#table-sublist').bootstrapTable('refresh',{url:'../adminMgr/device/loadDeviceList'});
		
});
$('#SearchUserbtn').click(function (e) {
	sKeyVal = $("#SearchUserTxt").val();	
		/*要更改bootstrapTable的url*/
	$('#table-sublist').bootstrapTable('refresh',{url:'../adminMgr/device/loadDeviceList'});	              
});
$("#SearchUserTxt").focus(function(){
  $("#SearchUserTxt").val("");
});

//$('.fixed-table-header').empty();
	});
	function sublistresponseHandler(res) {
	return {
	"rows": res.data.rows,
	"total": res.data.total
	};

}
function sublistqueryParams(params) {
	return {
		pagesize: params.limit,
		page: params.pageNumber,
		sKey: sKeyVal,
		orgId: currid
	};
}


function getorgidFormatter(value, row, index) {
	return currid;
}
function jumpTodevMngFormatter(value, row, index) {
            return '<a target="mainIframe" title="点击跳转到该设备的用户管理页" onclick="JumpTOOAMPage(\''+ row.sn+ '\',\'' + row.id+ '\',' + row.online+')"><i class="icon-edit"></i>' +row.sn +'</a>';
}
function cfgUploadFormatter(value, row, index) {
            return ['<a target="mainIframe" title="点击跳转到该设备的配置上传/下载页" onclick="JumpTOcfgUPPage(\''+ row.nid+'\')"><i class="icon-upload"></i></a>'					
                    ].join('');
}
function cfgMgrFormatter(value, row, index) {
if(row.lockCfg)
	 return ['<a title="该设备的配置管理已经被锁定" ><i class="icon-lock"></i></a>'					
                    ].join('');
else
     return ['<a target="mainIframe" title="点击跳转到该设备的配置管理页" onclick="JumpTOcfgPage(\''+ row.nid+'\')"><i class="icon-wrench"></i></a>'					
                    ].join('');
}
function operateFormatter(value, row, index) {
            return ['<a target="mainIframe" title="点击跳转到该设备的设备管理页" onclick="JumpTOOAMPage(\''+ row.id+'\')"><i class="icon-pencil"></i></a>'
                    ].join('');
}
function remarkFormatter(value, row, index) {
            return ['<a title="点击修改设备备注" onclick="viewSetRemarkForm(\''+ row.nid+'\')"><i class="icon-pencil"></i></a>'
                    ].join('');
}
function onlineFormatter(value, row, index) {
	if(row.online)
            return ['<i class="icon-user" style="color:#0088cc" title="在线"></i>'
                    ].join('');
	else
		return ['<i class="icon-user" title="离线"></i>'
                    ].join('');
}
//
function upgradeFormatter(value, row, index) {
	if(value == true){
		if(row.online == false){
			return ['<a title="设备离线无法进行该操作/可升级新版本"><font color="gray"><i class="icon-arrow-up"></i></font></a>'
                    ].join('');
		}else{
			return ['<a title="点击升级版本" onclick="upgrade(\''+ row.id+'\')"><i class="icon-arrow-up"></i></a>'
                    ].join('');
		}
		
	}else{
		return ['<a title="已是最新版本" ><font color="gray"><i class="icon-arrow-up"></i></font></a>'
                    ].join('');
	}
}

function upgrade(id) {
	$.ajax({
		url : '../adminMgr/device/upgradeDev',
		type : 'POST',
		dataType : 'json',
		timeout : 10000,
		cache : false,
		data : {
			devId : id
		},
		error : function () {
			bootbox.alert("版本升级异常", function () {});
			return false;
		},
		success : function (data) {
			if (data.resultCode != '10000') {
				bootbox.alert(data.resultMsg, function () {
					return;
				});
			} else {
				bootbox.alert(data.resultMsg, function () {
					$('#table-sublist').bootstrapTable('refresh');
				});
			}
		}

	})
}

function viewSetRemarkForm(devId)
{
    $('#devId').val(devId);
    $('#devRemarkModel').modal('show'); 
}
 $('#setDevRemarkBtn').click(function (e) {
	 e.preventDefault();
	 
	 var devId = $('#devId').val();
	 var remark = $('#devRemarkMsg').val();
	 $.ajax({  
               
                url: '../orgMgr/devCfg/modifyUserRemark', 
                type: 'POST',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{devId: devId,remark:remark},
				error : function() {
				
				 bootbox.alert("修改设备说明异常", function() {					
							//return;
						});
				},    
                success: function(data){
					if(data.resultCode != '10000'){					
						$('#devRemarkModel').modal('hide');
						
						bootbox.alert(data.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 $('#devRemarkModel').modal('hide'); 
						 bootbox.alert(data.resultMsg, function() {					
							$('#table-sublist').bootstrapTable('refresh');
						});		
					 	
					 }
					
				}               
								   
     })               
 });
function entersearch(event) {
	if (event.keyCode == 13) {
	sKeyVal = $("#SearchUserTxt").val();	
		/*要更改bootstrapTable的url*/
	$('#table-sublist').bootstrapTable('refresh',{url:'../adminMgr/device/loadDeviceList'});		
	}
}
	/*监听键盘事件*/
	$("#SearchUserTxt").keyup(function(){
		var searchKey = $("#SearchUserTxt").val();
		if(searchKey){
			$("#cleanBtn > i").attr("class","icon-remove");
			$("#cleanBtn").attr("onclick","cleanIput()");
		}else {
			$("#cleanBtn > i").attr("class","icon-search");
			$("#cleanBtn ").attr("onclick","");
		}
	});
	/*清空输入框*/
	function cleanIput(){
		$("#SearchUserTxt").val(""); //SearchUserTxt
		$("#SearchUserTxt").focus();
		$("#cleanBtn > i").attr("class","icon-search");
		$("#cleanBtn ").attr("onclick","");
	}
    </script>

</body>
</html>